import { Devcloud } from "../apiClass"
import { IResult } from "../../plugins/Interfaces"


export class EnvApi extends Devcloud {
  private baseUrl: string = this.path + 'env/';
  async page(param: any): Promise<IResult> {
    const resp = await this.client.post(this.baseUrl + "page", param)
    return resp.data
  }
  async list(param: any): Promise<IResult> {
    const resp = await this.client.post(this.baseUrl + "list", param)
    return resp.data
  }
  async insert(param: any): Promise<IResult> {
    const resp = await this.client.post(this.baseUrl + "insert", param)
    return resp.data
  }
  async update(param: any): Promise<IResult> {
    const resp = await this.client.post(this.baseUrl + "update", param)
    return resp.data
  }
  async delete(id: string): Promise<IResult> {
  const resp = await this.client.get(this.baseUrl + "delete", {"id": id})
  return resp.data
  }
  async get(id: string): Promise<IResult> {
    const resp = await this.client.get(this.baseUrl + "get", {"id": id})
    return resp.data
  }
  async copyEnvConfig(id: string, newEnv: string, newNamespace:string): Promise<IResult> {
    const resp = await this.client.post(this.baseUrl + "copyEnvConfig",
        {
          'sourceEnvId': id,
          'newEnv': newEnv,
          'newNamespace': newNamespace
        }
      )
    return resp.data
  }
  async copyProjectConfig(sourceEnvId: string, targetEnvId: string, projectIds: string[]): Promise<IResult> {
    const resp = await this.client.post(this.baseUrl + "copyProjectConfig",
        {
          'sourceEnvId': sourceEnvId,
          'targetEnvId': targetEnvId,
          "projectIds": projectIds
        }
      )
    return resp.data
  }
  async deleteNamespace(id: string): Promise<IResult> {
    const resp = await this.client.get(this.baseUrl + "deleteNamespcae", {id})
    return resp.data
  }
  async deleteProjectInfo(id: string): Promise<IResult> {
    const resp = await this.client.get(this.baseUrl + "deleteProjectInfo", {id})
    return resp.data
  }
  async initNamespace(id: string): Promise<IResult> {
    const resp = await this.client.post(this.baseUrl + "initNamespace", {id})
    return resp.data
  }
}